#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int k,a,b,x,y;
    cin>>k>>a>>b>>x>>y;
    int ans=0;
    if(x>y)
    {
        if(a>b)
        {
            if(k>=b)
            {
                if((k-b+1)%y)ans=1;
                ans+=(k-b+1)/y;
            }
        }
        else 
        {
            if(k>=b)
            {
                if((k-b+1)%y)ans=1;
                ans+=(k-b+1)/y;
                k-=y*ans;
            }
            if(k>=a)
            {
                if((k-a+1)%x)ans+=1;
                ans+=(k-a+1)/x;
            }
        }
    }
    else  
    {
        if(a>b)
        {
            if(k>=a)
            {
                if((k-a+1)%x)ans=1;
                ans+=(k-a+1)/x;
                k-=x*ans;
            }
            if(k>=b)
            {
                if((k-b+1)%y)ans+=1;
                ans+=(k-b+1)/y;
            }
        }
        else 
        {
            if(k>=a)
            {
                if((k-a+1)%x)ans=1;
                ans+=(k-a+1)/x;
            }
        }
    }
    ans=max(ans,0ll);
    cout<<ans<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}